


import 'package:bt_tool/basic/bt_controller.dart';
import 'package:bt_tool/basic/bt_language_tool.dart';
import 'package:bt_tool/widget/bt_text_field.dart';
import 'package:bt_tool/widget/bt_toast.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';

class TranslateResultController extends BTController{

  Map<String,dynamic> dataMap = {};
  var selectKey = "".obs;
  late BTTextFieldController textFieldController;

  @override
  void initState() {
    super.initState();
    dataMap = routerJsonTool.getMap("dataMap");
    selectKey.value = dataMap.keys.first;
    textFieldController = BTTextFieldController(
      textEditingController: TextEditingController(
        text: dataMap[selectKey.value]
      )
    );
  }

  changeKey(String key){
    selectKey.value = key;
    textFieldController.updateText(dataMap[key]);
  }

  copyClick(){
    String text = textFieldController.getText();
    Clipboard.setData(ClipboardData(text: text));
    BTToast.showToast("已复制到粘贴板".btTrans);
  }

  copyTextClick(){
    String text = textFieldController.getText();
    String resultText =  text.substring(2, text.length - 2);
    Clipboard.setData(ClipboardData(text: resultText));
    BTToast.showToast("已复制到粘贴板".btTrans);
  }

}